
$(document).ready(function() {
	initTable();
	
	$('#search').on('click',function(){
		initTable();
	});
});
var typeList;
$.post(basePath+"/dic/getDicListByCode",{"dicCode":"recovery_type"},function(data){
	typeList = data.data;
});

var table = new Table();
var initTable =function(){
	//筛选条件
	var orderNo = $('#orderNo').val();
	var recoveryType = $('#recoveryType').val()
	var sql ='?orderState=4';
	if(orderNo!=null&& orderNo!=''){
		sql += '&orderNo='+orderNo;
	}
	if(recoveryType!=null&& recoveryType!=''){
		sql += '&recoveryType='+recoveryType;
	}
	//表格加载的字段
    var cloumns = [
		    {'data': 'id','render': function (data) { return '<input type="checkbox" data-id="' + data + '" name="">';}},
		    {'data': 'order_no'},
		    {'data': 'picture','render': function (data) {return '<img style="max-width: 40px; max-height: 40px;"  src= "'+basePath+'/'+data+'" />';}},
		    {'data': 'nick_name'},
		    {'data': 'amount_money'},
		    {'data': 'recovery_type','render': 
		    	function (data) {
					for(var i=0;i<typeList.length;i++){
						if(data ==typeList[i].dic_value){
							return typeList[i].dic_name;
						}
					}
					return '';
				}
		    },
		    {'data': 'recovery_price'},
		    {'data': 'update_name'},
		    {'data': 'update_date'},
		    {'data': 'id','render':function(data,type,full){
		    	var url =basePath+"/order/toEditOrder?id="+data;
		    	var titles = '详情';
		    	var btn ='<a title="详情" href="javascript:;" onclick="toEdit(\''+titles+'\',\''+url+'\',\''+type+'\')" class="btn btn-primary  radius size-MINI" style="margin-right:10px;" >'+titles+'</a>';   
		    	if(full.recovery_state==0){
		    		btn +='<a title="通过" href="javascript:;" onclick="ship(\''+data+'\')" class="btn btn-secondary radius size-MINI" style="margin-right:10px;" >通过</a>';   
		    	}
		    	return table.delBtn(data)+btn;
		    	}}
		  ];
	//设置URL和加载的字段
    table.setting(basePath+"/order/getOrderList"+sql,basePath+"/order/delOrder",cloumns);
	//调用表格分页
    table.tablePage();
}

//发货窗口
function ship(id){
	//墨绿深蓝风
	layer.alert('确认通过回收审批吗', {
	  skin: 'layui-layer-molv', //样式类名
		  	btn: ['确认','取消'] //按钮
	}, function(index){
		 var data = {
				 'recovery_state':'1',
				 'id':id
		 }
		 
		$.ajax({
			type: "POST",
		    url: basePath + "/order/editOrder",
		    data: data,
		    dataType: "json",
		    success: function(r){
				if(r.code == 0){
					layer.close(index);
					initTable();
					layer.msg('通过审批');
				}else{
					layer.msg(r.msg);
				}
			}
		});  
		
	});
	}



